package com.example.springbootcore;

import com.example.springbootcore.config.AuthorProperties;
import com.example.springbootcore.config.TeacherProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;

//SpringBoot 非 application.properties 配置需要指定加载
@PropertySource(value={"my_application.properties"})
@SpringBootApplication
@Slf4j
public class SpringBootCoreApplication implements ApplicationRunner {

    @Value("${book.author}")
    private String author;

    @Value("${book.name}")
    private String name;

    @Value("${word.author}")
    private String wordAuthor;

    @Value("${word.name}")
    private String wordName;

    @Autowired
    private AuthorProperties authorProperties;

    @Autowired
    private TeacherProperties teacherProperties;

    public static void main(String[] args) {
        SpringApplication.run(SpringBootCoreApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info(author);
        log.info(name);
        log.info(wordAuthor);
        log.info(wordName);
        log.info(authorProperties.getName() + ":" + authorProperties.getAge());
        log.info(teacherProperties.getName() + ":" + teacherProperties.getAge());
    }
}
